using System;
using QAssetBundle;
using UnityEngine;
using QFramework;

namespace ProjectSurvival
{
	public partial class Bomb : GamePlayObject
	{
		private Collider2D _collider;

		private void Awake()
		{
			_collider = GetComponent<Collider2D>();
		}

		public static void Excute()
		{
			AudioKit.PlaySound(Bomb_wav.Bomb);
			GamePanel.FlashScreen.Trigger(); 
			CameraController.instance.ShakeCamera();
			foreach (var enemyObj in GameObject.FindGameObjectsWithTag("Enemy"))
			{
				var enemy = enemyObj.GetComponent<Enemy>();
				if (enemy && enemy.gameObject.activeSelf)  
				{
					DamageSystem.CalculateDamage(Global.SimpleBombDamage.Value,enemy);
				}
			}
			
		}
		void Start()
		{
			gameObject.OnTriggerEnter2DEvent((other) =>
			{
				if (other.GetComponent<CollectableArea>())
				{
					Excute();
					gameObject.DestroySelfGracefully();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		protected override Collider2D Collider => _collider;
	}
}
